import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/services.dart';
import 'photo_asset.dart';

class PhotoKit {
  static const MethodChannel _channel = const MethodChannel('photo_kit');

  static Future<String> get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future<List<PhotoAsset>> getAllPhoto() async {
    List photo = await _channel.invokeMethod('getAllPhoto');
    photo = photo.map((map) {
      PhotoAsset asset = PhotoAsset.fromMap(Map<String, dynamic>.from(map));
      return asset;
    }).toList();
    return photo;
  }

  static Future<Uint8List> requestImageData(
    String identity, {
    int width = -1,
    int height = -1,
  }) async {
    final data = await _channel.invokeMethod('requestImageData', {
      'identity': identity,
      'width': width,
      'height': height,
    });
    return data;
  }

  static Future<int> createTexture(String identity) async {
    final data = await _channel.invokeMethod('createTexture', {
      'identity': identity,
    });
    return data;
  }

  static Future<bool> updateTexture(
    String identity, {
    int width = -1,
    int height = -1,
  }) async {
    final data = await _channel.invokeMethod('updateTexture', {
      'identity': identity,
      'width': width,
      'height': height,
    });
    return data;
  }

  static Future<void> disposeTexture(String identity) async {
    await _channel.invokeMethod('disposeTexture', {
      'identity': identity,
    });
  }
}
